# README — Replication Package
**Paper:** *Does the Style of Misinformation Condition its Effects? An Experiment in Brazil*

This repository contains the materials to reproduce the data preparation steps for the paper. 

---

## 1) Repository Structure (current batch)

```
/ (project root)
├─ style.Rproj                 # RStudio project file (sets working directory)
├─ data.xlsx                   # Main survey dataset (Excel)
├─ scripts/
│   └─ 01_data_prep.R          # Data preparation script (this file; name suggested)
└─ data/
    └─ processed/              # Output folder created by the script for .rds files
```

> **Note:** If your script is not yet saved under `scripts/01_data_prep.R`, please save it with that name (or update the paths below to match your organization).

---

## 2) System Requirements

- **Operating System:** macOS, Windows, or Linux
- **Software:**
  - **R**: 4.3.x or later (4.4.x recommended)
  - **RStudio**: 2023.12 or later (recommended)
- **Hardware:** No high‑capacity server is required for the current step (data preparation). 

---

## 3) R Package Dependencies

The data-prep script uses the following packages:

- `tidyverse` (incl. `dplyr`, `tidyr`, `readr`)
- `naniar`
- `readxl`
- `Hmisc`

Install with:

```r
install.packages(c("tidyverse", "naniar", "readxl", "Hmisc"))
```

---

## 4) Input Data

- **`data.xlsx`**: Main dataset used for cleaning and variable construction.
  
---

## 5) Outputs (created by the data-prep script)

The script writes analysis‑ready `.rds` files to `data/processed/`:

- `data.rds` — master analysis dataset with constructed variables and weights
- `data_specific_prompts_items.rds`
- `data_specific_prompts.rds`
- `data_general_rumors_items.rds`
- `data_general_rumors.rds`
- `data_polarization_voters.rds`
- `data_polarization_politicians.rds`
- `data_polarization_lula_bolsonaro.rds`
- `data_polarization_attitudes_1_items.rds`
- `data_polarization_attitudes_1.rds`
- `data_polarization_attitudes_2_items.rds`
- `data_polarization_attitudes_2.rds`
- `data_polarization_game.rds`

These files support downstream model‑fitting, figure creation, and table generation.

---

## 6) How to Run (current stage)

1. Open the project by double‑clicking **`style.Rproj`** in RStudio.
2. Ensure **`data.xlsx`** is in the project root (same folder as the `.Rproj` file).
3. Create the folder structure (if not already present):
   ```r
   dir.create("scripts", showWarnings = FALSE)
   dir.create(file.path("data", "processed"), recursive = TRUE, showWarnings = FALSE)
   ```
4. Save the data‑preparation script as **`scripts/01_data_prep.R`**.  
5. Install dependencies (see Section 3).  
6. Run the data-preparation script:
   ```r
   source("scripts/01_data_prep.R")
   ```
7. Confirm that `.rds` outputs were written to `data/processed/` (see list above).

---

## 7) Notes & Assumptions

- Missing values are defined as any of `{96, 97, 98, 99, "N/A"}` prior to variable construction.
- Labels are assigned using `Hmisc::label` to facilitate readable tables/figures downstream.
- The script expects the questionnaire columns (`Q*` items and other names like `GRUPO`, `REGION`, `Q4R`, etc.) to be present in `data.xlsx` and coded as in the fielded instrument.
- Weight creation: the script builds an inverse‑propensity weight using within‑group treatment shares by `ideo_group`. 

---


## 8) Excel workbook structure (`data.xlsx`)

The Excel file contains multiple sheets:

- **`UCTEES_264057_20240805`** — **Main dataset** used for replication.
- **`labels`** — Variable/value labels (codebook metadata).
- **`variables`** — Variable list / descriptions.
- **`codigos`** — Coding schemes / value codes per question.

### How the scripts read it

By default, `scripts/01_data_prep.R` called `readxl::read_excel("data.xlsx")`, which reads the **first** sheet. To ensure the correct sheet is loaded, set the `sheet` argument explicitly:

> If the dataset sheet name changes in your replications, update the `sheet =` argument accordingly (or use `sheet = 1` if you keep the dataset as the first sheet).

> A different excel file called codebook.csv was created to translate the variable description to english


## 9) Contact

If you have questions about this replication package, please contact the authors.

- *Corresponding author:* Fernando Barros de Mello (fernando.barros@uc3m.es)
- Paper: *Does the Style of Misinformation Condition its Effects?*